package com.woniuxy.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectCount;
import com.woniuxy.platform.common.PlatformResultCode;
import com.woniuxy.platform.infra.model.PlatformUser;
import com.woniuxy.platform.infra.mapper.PlatformUserMapper;
import com.woniuxy.platform.service.PlatformUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import exception.MallException;
import org.springframework.stereotype.Service;
import result.CommonResultCodeEnum;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2023-07-19
 */
@Service
public class PlatformUserServiceImpl extends ServiceImpl<PlatformUserMapper, PlatformUser> implements PlatformUserService {

    @Override
    public void addUser(String account, String password) {
        PlatformUser user = getOne(new QueryWrapper<PlatformUser>().eq("account", account));
        if (user!=null){
            throw new MallException(PlatformResultCode.ACCOUNT_EXISITS);
        }
        PlatformUser newUser = new PlatformUser();
        newUser.setAccount(account);
        newUser.setPassword(password);
        save(newUser);
    }


    @Override
    public PlatformUser login(String account, String password) {
        PlatformUser user = getOne(new QueryWrapper<PlatformUser>().eq("account", account).eq("password", password));
        if (user==null){
            throw new MallException(PlatformResultCode.LOGIN_ERROR);
        }

        return user;
    }


//    @Override
//    public PlatformUser login() {
//
//    }
}
